package bki.adapters;

import java.util.ArrayList;

import bki.kiducate.HomeActivity;
import bki.kiducate.R;
import bki.objects.HomeObject;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class HomeAdapter extends BaseAdapter{
	ArrayList m_arrLImg;
	LayoutInflater m_layoutInf;
	Context m_context;
	public HomeAdapter(Context i_context, ArrayList i_arrL){
		this.m_arrLImg = i_arrL;
		m_context = i_context;
		m_layoutInf = LayoutInflater.from(i_context);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return m_arrLImg.size();
	}
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return m_arrLImg.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
//		ImageView v_imgView;
//		if (convertView == null){
//			v_imgView = new ImageView(m_context);
//		} else {
//			v_imgView = (ImageView)convertView;
//		}
//		v_imgView.setBackgroundResource((Integer) m_arrLImg.get(position));
//		//v_imgView.getLayoutParams().height=10;
//		return v_imgView;
		ImgHolder v_ImgHolder;
		if (convertView == null) {
			convertView = m_layoutInf.inflate(R.layout.home_item, null);
			v_ImgHolder = new ImgHolder();
			v_ImgHolder.imgView = (ImageView) convertView.findViewById(R.id.imageView1);
			convertView.setTag(v_ImgHolder);
		} else {
			v_ImgHolder = (ImgHolder) convertView.getTag();
		}
		v_ImgHolder.imgView.setBackgroundResource((Integer) m_arrLImg.get(position));
		
		v_ImgHolder.imgView.getLayoutParams().height = (HomeActivity.mHeight*8/9-30)/2;
		return convertView;
	}
	static class ImgHolder{
		ImageView imgView;
	}
}
